#ifndef USERMANAGER_H
#define USERMANAGER_H

#include <QMainWindow>
#include <QSqlTableModel>

class ChangePasswordDialog;

namespace Ui {
class UserManager;
}

class UserManager : public QMainWindow
{
    Q_OBJECT

public:
    explicit UserManager(QWidget *parent = nullptr);
    ~UserManager();

    void setCurrentUserInfo(int userId, const QString &role);

protected:
    void closeEvent(QCloseEvent *event) override;

private slots:
    void onOpenDatabase();
    void onAddUser();
    void onInsertUser();
    void onSaveChanges();
    void onCancelChanges();
    void onDeleteUser();
    void onSearchUser();
    void onResetPassword();
    void onChangePassword();

private:
    Ui::UserManager *ui;
    QSqlTableModel *sqlModel;
    ChangePasswordDialog *changePasswordDialog;

    void setupConnections();
    void editHeaderData();
    QString hashPassword(const QString &password);
    bool validatePasswordStrength(const QString &password);

    QString currentUserRole;
    int currentUserId;

     void applyUserPermissions();
     void setupUserTableViewPermissions();
     void loadUserData(); // 自动加载用户数据
};


#endif // USERMANAGER_H
